Skip to content

Add PrintTAFn flag for targeted type analysis printing #142809

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 26, 2025

Conversation

KMJ-007
Copy link
Contributor

@KMJ-007 KMJ-007 commented Jun 20, 2025

Summary

This PR adds a new PrintTAFn flag to the -Z autodiff option that allows printing type analysis information for a specific function, rather than all functions.

Changes

New Flag

  • Added PrintTAFn=<function_name> option to -Z autodiff
  • Usage: -Z autodiff=Enable,PrintTAFn=my_function_name

Implementation Details

  • Rust side: Added PrintTAFn(String) variant to AutoDiff enum
  • Parser: Updated parse_autodiff to handle PrintTAFn=<function_name> syntax with proper error handling
  • FFI: Added set_print_type_fun function to interface with Enzyme's FunctionToAnalyze command line option
  • Documentation: Updated help text and documentation for the new flag

Files Modified

  • compiler/rustc_session/src/config.rs: Added PrintTAFn(String) variant
  • compiler/rustc_session/src/options.rs: Updated parser and help text (now shows PrintTAFn in the list)
  • compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs: Added FFI function and static variable
  • compiler/rustc_codegen_llvm/src/back/lto.rs: Added handling for new flag
  • src/doc/rustc-dev-guide/src/autodiff/flags.md: Updated documentation
  • src/doc/unstable-book/src/compiler-flags/autodiff.md: Updated documentation

Testing

The flag can be tested with:

rustc +enzyme -Z autodiff=Enable,PrintTAFn=square test.rs

This will print type analysis information only for the function named "square" instead of all functions.

Error Handling

The parser includes proper error handling:

  • Missing argument: PrintTAFn without =<function_name> will show an error
  • Unknown options: Invalid autodiff options will be reported

r? @ZuseZ4

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-rustc-dev-guide Area: rustc-dev-guide F-autodiff `#![feature(autodiff)]` S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 20, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jun 20, 2025

Some changes occurred in compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs

cc @ZuseZ4

The rustc-dev-guide subtree was changed. If this PR only touches the dev guide consider submitting a PR directly to rust-lang/rustc-dev-guide otherwise thank you for updating the dev guide with your changes.

cc @BoxyUwU, @jieyouxu, @Kobzol

Some changes occurred in src/doc/unstable-book/src/compiler-flags/autodiff.md

cc @ZuseZ4

@rust-log-analyzer

This comment has been minimized.

@ZuseZ4
Copy link
Member

ZuseZ4 commented Jun 22, 2025

You need to run a formater on the cpp files manually. You can do build/x86_64-unknown-linux-gnu/llvm/bin/clang-format compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp -i

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@KMJ-007 KMJ-007 requested a review from ZuseZ4 June 23, 2025 10:26
@ZuseZ4
Copy link
Member

ZuseZ4 commented Jun 24, 2025

ust squash all commits here into one. Also you'll have to first add a commit which updates the enzyme submodule to b5098d515d5e1bd0f5470553bc0d18da9794ca8b, and then have a second commit which introduces this flag.
Afterwards lgtm.

KMJ-007 added 2 commits June 25, 2025 02:11
Signed-off-by: Karan Janthe <karanjanthe@gmail.com>
Signed-off-by: Karan Janthe <karanjanthe@gmail.com>
@rust-cloud-vms rust-cloud-vms bot force-pushed the ad-type-analysis-flag branch from 7f44fb8 to 7b1c89f Compare June 25, 2025 02:12
@rustbot
Copy link
Collaborator

rustbot commented Jun 25, 2025

Some changes occurred in src/tools/enzyme

cc @ZuseZ4

@rustbot
Copy link
Collaborator

rustbot commented Jun 25, 2025

⚠️ Warning ⚠️

  • Some commits in this PR modify submodules.

@ZuseZ4
Copy link
Member

ZuseZ4 commented Jun 25, 2025

@bors r+

@bors
Copy link
Collaborator

bors commented Jun 25, 2025

📌 Commit 7b1c89f has been approved by ZuseZ4

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 25, 2025
SciMind2460 added a commit to SciMind2460/rust that referenced this pull request Jun 25, 2025
…useZ4

Add PrintTAFn flag for targeted type analysis printing

## Summary
This PR adds a new `PrintTAFn` flag to the `-Z autodiff` option that allows printing type analysis information for a specific function, rather than all functions.

## Changes

### New Flag
- Added `PrintTAFn=<function_name>` option to `-Z autodiff`
- Usage: `-Z autodiff=Enable,PrintTAFn=my_function_name`

### Implementation Details
- **Rust side**: Added `PrintTAFn(String)` variant to `AutoDiff` enum
- **Parser**: Updated `parse_autodiff` to handle `PrintTAFn=<function_name>` syntax with proper error handling
- **FFI**: Added `set_print_type_fun` function to interface with Enzyme's `FunctionToAnalyze` command line option
- **Documentation**: Updated help text and documentation for the new flag

### Files Modified
- `compiler/rustc_session/src/config.rs`: Added `PrintTAFn(String)` variant
- `compiler/rustc_session/src/options.rs`: Updated parser and help text (now shows `PrintTAFn` in the list)
- `compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs`: Added FFI function and static variable
- `compiler/rustc_codegen_llvm/src/back/lto.rs`: Added handling for new flag
- `src/doc/rustc-dev-guide/src/autodiff/flags.md`: Updated documentation
- `src/doc/unstable-book/src/compiler-flags/autodiff.md`: Updated documentation

## Testing
The flag can be tested with:
```bash
rustc +enzyme -Z autodiff=Enable,PrintTAFn=square test.rs
```

This will print type analysis information only for the function named "square" instead of all functions.

## Error Handling
The parser includes proper error handling:
- Missing argument: `PrintTAFn` without `=<function_name>` will show an error
- Unknown options: Invalid autodiff options will be reported

r? `@ZuseZ4`
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jun 25, 2025
…useZ4

Add PrintTAFn flag for targeted type analysis printing

## Summary
This PR adds a new `PrintTAFn` flag to the `-Z autodiff` option that allows printing type analysis information for a specific function, rather than all functions.

## Changes

### New Flag
- Added `PrintTAFn=<function_name>` option to `-Z autodiff`
- Usage: `-Z autodiff=Enable,PrintTAFn=my_function_name`

### Implementation Details
- **Rust side**: Added `PrintTAFn(String)` variant to `AutoDiff` enum
- **Parser**: Updated `parse_autodiff` to handle `PrintTAFn=<function_name>` syntax with proper error handling
- **FFI**: Added `set_print_type_fun` function to interface with Enzyme's `FunctionToAnalyze` command line option
- **Documentation**: Updated help text and documentation for the new flag

### Files Modified
- `compiler/rustc_session/src/config.rs`: Added `PrintTAFn(String)` variant
- `compiler/rustc_session/src/options.rs`: Updated parser and help text (now shows `PrintTAFn` in the list)
- `compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs`: Added FFI function and static variable
- `compiler/rustc_codegen_llvm/src/back/lto.rs`: Added handling for new flag
- `src/doc/rustc-dev-guide/src/autodiff/flags.md`: Updated documentation
- `src/doc/unstable-book/src/compiler-flags/autodiff.md`: Updated documentation

## Testing
The flag can be tested with:
```bash
rustc +enzyme -Z autodiff=Enable,PrintTAFn=square test.rs
```

This will print type analysis information only for the function named "square" instead of all functions.

## Error Handling
The parser includes proper error handling:
- Missing argument: `PrintTAFn` without `=<function_name>` will show an error
- Unknown options: Invalid autodiff options will be reported

r? ``@ZuseZ4``
bors added a commit that referenced this pull request Jun 25, 2025
Rollup of 7 pull requests

Successful merges:

 - #142146 (Withdraw the claim `extern "C-cmse-nonsecure-*"` always matches `extern "C"`)
 - #142200 (`tests/ui`: A New Order [8/N])
 - #142724 (Add runtime check to avoid overwrite arg in `Diag`)
 - #142809 (Add PrintTAFn flag for targeted type analysis printing)
 - #142976 (Check CoerceUnsized impl validity before coercing)
 - #142992 (Convert some ABI tests to use `extern "rust-invalid"`)
 - #143000 (Make `Sub`, `Mul`, `Div` and `Rem`  `const_traits`)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 69b11c6 into rust-lang:master Jun 26, 2025
10 checks passed
@rustbot rustbot added this to the 1.90.0 milestone Jun 26, 2025
rust-timer added a commit that referenced this pull request Jun 26, 2025
Rollup merge of #142809 - KMJ-007:ad-type-analysis-flag, r=ZuseZ4

Add PrintTAFn flag for targeted type analysis printing

## Summary
This PR adds a new `PrintTAFn` flag to the `-Z autodiff` option that allows printing type analysis information for a specific function, rather than all functions.

## Changes

### New Flag
- Added `PrintTAFn=<function_name>` option to `-Z autodiff`
- Usage: `-Z autodiff=Enable,PrintTAFn=my_function_name`

### Implementation Details
- **Rust side**: Added `PrintTAFn(String)` variant to `AutoDiff` enum
- **Parser**: Updated `parse_autodiff` to handle `PrintTAFn=<function_name>` syntax with proper error handling
- **FFI**: Added `set_print_type_fun` function to interface with Enzyme's `FunctionToAnalyze` command line option
- **Documentation**: Updated help text and documentation for the new flag

### Files Modified
- `compiler/rustc_session/src/config.rs`: Added `PrintTAFn(String)` variant
- `compiler/rustc_session/src/options.rs`: Updated parser and help text (now shows `PrintTAFn` in the list)
- `compiler/rustc_codegen_llvm/src/llvm/enzyme_ffi.rs`: Added FFI function and static variable
- `compiler/rustc_codegen_llvm/src/back/lto.rs`: Added handling for new flag
- `src/doc/rustc-dev-guide/src/autodiff/flags.md`: Updated documentation
- `src/doc/unstable-book/src/compiler-flags/autodiff.md`: Updated documentation

## Testing
The flag can be tested with:
```bash
rustc +enzyme -Z autodiff=Enable,PrintTAFn=square test.rs
```

This will print type analysis information only for the function named "square" instead of all functions.

## Error Handling
The parser includes proper error handling:
- Missing argument: `PrintTAFn` without `=<function_name>` will show an error
- Unknown options: Invalid autodiff options will be reported

r? ```@ZuseZ4```
github-actions bot pushed a commit to rust-lang/rustc-dev-guide that referenced this pull request Jun 26, 2025
Rollup of 7 pull requests

Successful merges:

 - rust-lang/rust#142146 (Withdraw the claim `extern "C-cmse-nonsecure-*"` always matches `extern "C"`)
 - rust-lang/rust#142200 (`tests/ui`: A New Order [8/N])
 - rust-lang/rust#142724 (Add runtime check to avoid overwrite arg in `Diag`)
 - rust-lang/rust#142809 (Add PrintTAFn flag for targeted type analysis printing)
 - rust-lang/rust#142976 (Check CoerceUnsized impl validity before coercing)
 - rust-lang/rust#142992 (Convert some ABI tests to use `extern "rust-invalid"`)
 - rust-lang/rust#143000 (Make `Sub`, `Mul`, `Div` and `Rem`  `const_traits`)

r? `@ghost`
`@rustbot` modify labels: rollup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-rustc-dev-guide Area: rustc-dev-guide F-autodiff `#![feature(autodiff)]` S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants